﻿#include "GameGlobal.h"

#include "GameLevelScene.h"

#include "TitleScene.h"
#include "HelloWorldScene.h"

#include "ControlLayer.h"
#include "GameBGLayer.h"
#include "GameUILayer.h"
#include "StruggleLayer.h"

#include "SpriteBrick.h"

CCScene* GameLevelScene::scene(){
	CCScene * scene = NULL;
	do 
	{
		scene = CCScene::create();
		CC_BREAK_IF(! scene);

		GameBGLayer* pGameBGLayer = GameBGLayer::create();
		CC_BREAK_IF(! pGameBGLayer);
		scene->addChild(pGameBGLayer,KBGLayer,KBGLayer);

		GameLevelScene * pbglayer = GameLevelScene::create();
		CC_BREAK_IF(! pbglayer);
		scene->addChild(pbglayer,kSceneLayer,kSceneLayer);

		ControlLayer* pControlLayer = ControlLayer::create();
		CC_BREAK_IF(! pControlLayer);
		scene->addChild(pControlLayer,kControlLayer,kControlLayer);

		StruggleLayer* pStruggleLayer = StruggleLayer::create();
		CC_BREAK_IF(! pStruggleLayer);
		scene->addChild(pStruggleLayer,kStruggleLayer,kStruggleLayer);

		GameUILayer* pUILayer = GameUILayer::create();
		CC_BREAK_IF(! pUILayer);
		scene->addChild(pUILayer,kUILayer,kUILayer);

	} while (0);

	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
bool GameLevelScene::init()
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(! CCLayer::init());

		SpriteBrick*  pssSprite = SpriteBrick::CreateWithTexture("images/Card/Plants/Peashooter.png","images/Card/Plants/PeashooterG.png");
		pssSprite->setPosition(VisibleRect::leftTop());
		pssSprite->setAnchorPoint(RectLayout::TopLeft());
		pssSprite->setVisible(false);
		this->addChild(pssSprite,kPeaShooterSpriteBrick,kPeaShooterSpriteBrick);
		
		this->schedule(schedule_selector(GameLevelScene::initUIContent),8.0);

		bRet = true;

	} while (0);

	return bRet;
}

void GameLevelScene::initUIContent( float dt )
{
	SpriteBrick* psb = (SpriteBrick*)this->getChildByTag(kPeaShooterSpriteBrick);
	psb->setVisible(true);
}